package com.tianma315.admin.product.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.stereotype.Service;

import com.tianma315.admin.product.dao.DestructionDao;
import com.tianma315.admin.product.domain.DestructionDO;
import com.tianma315.admin.product.service.DestructionService;

import java.util.Date;

/**
 * 
 * <pre>
 * 销毁信息
 * </pre>
 * <small> 2019-07-15 17:14:03 | wen</small>
 */
@Service
public class DestructionServiceImpl extends CoreServiceImpl<DestructionDao, DestructionDO> implements DestructionService {

    @Override
    public Page<DestructionDO> getDestructionPage(Integer pageNumber, Integer pageSize, DestructionDO destructionDO) {
        // 查询列表数据
        Page<DestructionDO> page = new Page<>(pageNumber, pageSize);
        Wrapper<DestructionDO> wrapper = new EntityWrapper<DestructionDO>();
        wrapper.eq("state",0);
        wrapper.like("product_name",destructionDO.getProductName());
        page = selectPage(page, wrapper);
        int total = selectCount(wrapper);
        page.setTotal(total);
        return page;
    }

    @Override
    public Boolean addDestruction(DestructionDO destructionDO) {
        destructionDO.setCreateDate(new Date());
        destructionDO.setState(0);
        Boolean result = insert(destructionDO);
        return result;
    }

    @Override
    public Boolean deleteDestruction(Integer destructionId) {
        DestructionDO destructionDO = new DestructionDO();
        destructionDO.setState(1);
        destructionDO.setDestructionId(destructionId);
        Boolean result = updateById(destructionDO);
        return result;
    }
}
